home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / lang / Python16_Src.lha / Python16_Source / Include / stringobject.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-03  |  2.7 KB  |  78 lines

  1. #ifndef Py_STRINGOBJECT_H
  2. #define Py_STRINGOBJECT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6.  
  7. /* String object interface */
  8.  
  9. /*
  10. Type PyStringObject represents a character string.  An extra zero byte is
  11. reserved at the end to ensure it is zero-terminated, but a size is
  12. present so strings with null bytes in them can be represented.  This
  13. is an immutable object type.
  14.  
  15. There are functions to create new string objects, to test
  16. an object for string-ness, and to get the
  17. string value.  The latter function returns a null pointer
  18. if the object is not of the proper type.
  19. There is a variant that takes an explicit size as well as a
  20. variant that assumes a zero-terminated string.  Note that none of the
  21. functions should be applied to nil objects.
  22. */
  23.  
  24. /* Two speedup hacks.  Caching the hash saves recalculation of a
  25.    string's hash value.  Interning strings (which requires hash
  26.    caching) tries to ensure that only one string object with a given
  27.    value exists, so equality tests are one pointer comparison.
  28.    Together, these can speed the interpreter up by as much as 20%.
  29.    Each costs the size of a long or pointer per string object.  In
  30.    addition, interned strings live until the end of times.  If you are
  31.    concerned about memory footprint, simply comment the #define out
  32.    here (and rebuild everything!). */
  33. #define CACHE_HASH
  34. #ifdef CACHE_HASH
  35. #define INTERN_STRINGS
  36. #endif
  37.  
  38. typedef struct {
  39.     PyObject_VAR_HEAD
  40. #ifdef CACHE_HASH
  41.     long ob_shash;
  42. #endif
  43. #ifdef INTERN_STRINGS
  44.     PyObject *ob_sinterned;
  45. #endif
  46.     char ob_sval[1];
  47. } PyStringObject;
  48.  
  49. extern DL_IMPORT(PyTypeObject) PyString_Type;
  50.  
  51. #define PyString_Check(op) ((op)->ob_type == &PyString_Type)
  52.  
  53. extern DL_IMPORT(PyObject *) PyString_FromStringAndSize Py_PROTO((const char *, int));
  54. extern DL_IMPORT(PyObject *) PyString_FromString Py_PROTO((const char *));
  55. extern DL_IMPORT(int) PyString_Size Py_PROTO((PyObject *));
  56. extern DL_IMPORT(char *) PyString_AsString Py_PROTO((PyObject *));
  57. extern DL_IMPORT(void) PyString_Concat Py_PROTO((PyObject **, PyObject *));
  58. extern DL_IMPORT(void) PyString_ConcatAndDel Py_PROTO((PyObject **, PyObject *));
  59. extern DL_IMPORT(int) _PyString_Resize Py_PROTO((PyObject **, int));
  60. extern DL_IMPORT(PyObject *) PyString_Format Py_PROTO((PyObject *, PyObject *));
  61.  
  62. #ifdef INTERN_STRINGS
  63. extern DL_IMPORT(void) PyString_InternInPlace Py_PROTO((PyObject **));
  64. extern DL_IMPORT(PyObject *) PyString_InternFromString Py_PROTO((const char *));
  65. #else
  66. #define PyString_InternInPlace(p)
  67. #define PyString_InternFromString(cp) PyString_FromString(cp)
  68. #endif
  69.  
  70. /* Macro, trading safety for speed */
  71. #define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)
  72. #define PyString_GET_SIZE(op)  (((PyStringObject *)(op))->ob_size)
  73.  
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif /* !Py_STRINGOBJECT_H */
  78.